/// @tags: MonoQueue
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 1;

struct Drop {
  int x, y;
  bool operator<(const Drop &rhs) const { return x < rhs.x; }
} drops[maxn];

std::deque<int> q_max, q_min;

int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) {
    cin >> drops[i].x >> drops[i].y;
  }
  std::sort(drops + 1, drops + n + 1);
  int ans = 0x7fffffff;
  q_max.push_back(1);
  q_min.push_back(1);
  for (int l = 1, r = 1; l <= n; ++l) {
    while (!q_max.empty() && q_max.front() < l) q_max.pop_front();
    while (!q_min.empty() && q_min.front() < l) q_min.pop_front();
    while (r < n && drops[q_max.front()].y - drops[q_min.front()].y < d) {
      ++r;
      while (!q_max.empty() && drops[q_max.back()].y < drops[r].y) q_max.pop_back();
      q_max.push_back(r);
      while (!q_min.empty() && drops[q_min.back()].y > drops[r].y) q_min.pop_back();
      q_min.push_back(r);
    }
    if (drops[q_max.front()].y - drops[q_min.front()].y >= d)
      ans = std::min(ans, drops[r].x - drops[l].x);
  }
  cout << (ans == 0x7fffffff ? -1 : ans);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P2698 [USACO12MAR] Flowerpot S.in", "r", stdin);
  freopen("P2698 [USACO12MAR] Flowerpot S.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
